package org.jeecg.config.sign.filters;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Component
@WebFilter(urlPatterns = "/*")
public class XssFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        log.info("\nXssFilter doFilter: {}", ((HttpServletRequest) request).getRequestURL());
        XssHttpServletRequestWrapper xssRequestWrapper = new XssHttpServletRequestWrapper(request);
        filterChain.doFilter(xssRequestWrapper, response);
    }

    @Override
    public void destroy() {

    }
}
